﻿using Application.Sale_dService;
using Domain.Entity.ord;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WMSManage.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]//需要鉴权
    public class Sale_dController : ControllerBase
    {
        private readonly ISale_dService sale_DService;

        public Sale_dController(ISale_dService sale_DService)
        {
            this.sale_DService = sale_DService;
        }


        /// <summary>
        /// 添加销售明细单
        /// </summary>
        /// <param name="addSale_DDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddSale_d(AddSale_dDto addSale_DDto)
        {
            return await sale_DService.AddSale_d(addSale_DDto);
        }


        /// <summary>
        /// 根据销售单id查询明细
        /// </summary>
        /// <param name="saleid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<Sale_d>> GetSale_ds(int saleid)
        {
            return await sale_DService.GetSale_ds(saleid);
        }


        /// <summary>
        /// 删除销售明细单
        /// </summary>
        /// <param name="saleid"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> DeleteSale_d(int saleid)
        {
            return await sale_DService.DeleteSale_d(saleid);
        }


        [HttpPut]
        public async Task<int> UpdateRNum(int saledid, int returnnum, int newnum)
        {
            return await sale_DService.UpdateRNum(saledid, returnnum, newnum);
        }
    }
}
